﻿using System;
using System.Collections.Generic;
using System.Text;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.IDAL;
using OgilvyOne.UKNow.DALFactory;

using ECCIT;
using ECCIT.Security;

namespace OgilvyOne.UKNow.BLL
{
    public class MemberBLL
    {
        public int LanguageID { get; set; }
        public MemberBLL(int langID)
        {
            this.LanguageID = langID;
        }

        //保存会员信息
        public ResultInfo Save(MemberModel model)
        {
            IDALMember use = MemberDALFactory.Create(LanguageID);
            return use.Save(model);
        }

        public IList<MemberModel> Check(string username)
        {
            IDALMember use = MemberDALFactory.Create(LanguageID);
            return use.Check(username);
        }

        public IList<MemberModel> CheckEmail(string email)
        {
            IDALMember use = MemberDALFactory.Create(LanguageID);
            return use.CheckEmail(email);
        }

        public ResultInfo SignIn(string memberEmail, string password)
        {
            ResultInfo result = new ResultInfo(false);

            string epwd = MD5Crypto.GetMD5Hash(password);   //对密码进行MD5加密
            result = MemberDALFactory.Create(LanguageID).SignIn(memberEmail, epwd);
            return result;
        }

        //根据会员id 获取该对象
        public MemberModel getMemberByID(int? mid)
        {
            IDALMember use = MemberDALFactory.Create(LanguageID);
            return use.GetMemberModelByID(mid);
        }

        //获取所有会员
        public IList<MemberModel> selectmember()
        {
            IDALMember use = MemberDALFactory.Create(LanguageID);
            return use.GetAllMemberModels();
        }

        //根据时间条件获取会员
        public IList<MemberModel> GetMemberByTime(string staTme, string endTime)
        {
            IDALMember use = MemberDALFactory.Create(LanguageID);
            return use.QueryTime(staTme, endTime);
        }
    }
}
